package com.dc.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.persistence.*;
import java.util.Date;
import java.util.Objects;

@Data
@AllArgsConstructor
@NoArgsConstructor
@Entity
@Table(name = "t_calibration_water_clean_point_child")
public class CalibrationWaterCleanPointChildEntity {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @Column(name = "device_no", length = 50)
    private String deviceNo;      // 设备编号

    @Column(name = "power")
    private Double power;       // 设备功率(kw)

    @Column(name = "time_num")
    private Double timeNum;     //  使用时间

    @Column(name = "power_by_hour")
    private Double powerByHour; // 总有功电能(kw/h)

    @Transient
    private Long pid;     // 传递 calibration_water_clean_point_id 参数

    // persist对级联新增有影响，remove对级联删除有影响，merge对级联修改有影响，refresh对级联查询有影响
    @JsonIgnoreProperties(value = { "inner" })
    @JsonIgnore
    @ManyToOne()
    @JoinColumn(name = "calibration_water_clean_point_id", referencedColumnName = "id")
    private CalibrationWaterCleanPointEntity calibrationWaterCleanPointEntity;

    @Override
    public String toString() {
        return "CalibrationWaterCleanPointChildEntity{" +
                "pid=" + pid +
                ", powerByHour=" + powerByHour +
                ", timeNum=" + timeNum +
                ", power=" + power +
                ", deviceNo='" + deviceNo + '\'' +
                ", id=" + id +
                ", calibrationWaterCleanPointEntityId=" + calibrationWaterCleanPointEntity.getId() +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof CalibrationWaterCleanPointChildEntity)) return false;
        CalibrationWaterCleanPointChildEntity that = (CalibrationWaterCleanPointChildEntity) o;
        return Objects.equals(id, that.id);
    }

    @Override
    public int hashCode() {
        return Objects.hashCode(id);
    }
}
